package com.hardroid.workload.workcalc;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.util.Log;

import com.hardroid.workload.utils.Singleton;

/**
 * @author hartono
 *
 */
public class ObsvProject implements Serializable{
	
	public static final int OBSV_DAY_COUNT = 1;
	
	/**
	 * Project Name
	 */
	public String projectName;
	/**
	 * Observer Name
	 */
	public String observerName;
	/**
	 * Company Name
	 */
	public String companyName;
	/**
	 * Company Location
	 */
	public String companyLocation;
		
	/**
	 * Observation Description => jumlah tally dan observation gapnya
	 */
	public ObsvDesc obsvDesc;
	
	/**
	 * Project Notes
	 */
	public String projectNotes;
		
	/**
	 * List of Employer 
	 */
	public ArrayList<Employer> lEmployer;
	
	/**
	 * List of unit kerja
	 */
	public ArrayList<WorkUnit> lWorkUnit;
	
	public static enum ProjectStatus{
		PROJECT_FINISHED // saved and finished
		, PROJECT_NOT_FINISHED//  saved temporary
		,PROJECT_NOT_SAVED// not saved
	}
	
	/**
	 * Project status -> finished or not finished
	 */
	public ProjectStatus projectStatus;		
	
	/**
	 * Default Constructor
	 */
	public ObsvProject() {
		this.projectStatus = ProjectStatus.PROJECT_NOT_SAVED;		
		obsvDesc = new ObsvDesc();	
		lEmployer = new ArrayList<Employer>();
		lWorkUnit = new ArrayList<WorkUnit>();
	}
	
	public void saveProject(String fileName){
		
	}
	
	public void saveProject(){
		
	}
	
	public void saveAndFinishProject(){
		
	}
		
	public void saveAndFinishProject(String fileName){
		
	}
		
	/**
	 * Edit project attributes
	 * @param name
	 * @param observer
	 * @param company
	 * @param location
	 * @param notes
	 */
	public void editProjectDesc(String name,String observer, String company, String location,String notes){
		this.projectName= name;
		this.companyName = company;
		this.companyLocation = location;
		this.observerName = observer;
		this.projectNotes = notes;
	}
	
	/**
	 * @return List of employer
	 */
	public ArrayList<Employer> getEmployers(){
		return lEmployer;
	}
	
	
	/** Remove responden
	 * @param position
	 */
	public void removeResponden (int position){
		lEmployer.remove(position);		
	}
	
	/**
	 *  Add new responden
	 * @param name
	 * @param division
	 * @param unit
	 * @param job
	 * @param isMale
	 * @param isStructural
	 */
	public void addResponden(String name, String division, String unit, String job , boolean isMale, boolean isStructural){
		Employer e = new Employer();
		e.name  =name;
		e.division=division;
		e.unit=unit;
		e.job=job;
		e.male = isMale;
		e.structural = isStructural;
		
		
		ObsvDay day = new ObsvDay(Singleton.todayReference,e);
		e.sheet.lObsvDay.add(day);
		lEmployer.add(e);
		
	}	
	
	
	
	
	/**
	 *  Mengecek apakah project dapat diselesaikan untuk melihat hasil observasi
	 * @return
	 */
	public boolean isProjectCanBeFinished(){
		for (Employer e : lEmployer){
			if (!e.isDataEnough()){
				return false;
			}
		}
		return true;
	}
	
	/** Mendapatkan list of id employer yang datanya belum selesai diisi seluruhnya
	 * @return
	 */
	public List<Integer> getEmployerDataNotEnough(){
		ArrayList<Integer> list = new ArrayList<Integer>();
		int i= 0;
		for (Employer e : lEmployer){
			if (!e.isDataEnough()){
				Log.i("ObsvProject", i+" added to list");
				list.add(i);
			}
			i++;
		}
		return list;
	}
			
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return projectName + " " + observerName + " " + companyName+" "+companyLocation+ " "+projectNotes+" ";
	}

	public void removeUnit(int selectionPos) {
		// TODO Auto-generated method stub
		lWorkUnit.remove(selectionPos);		
	}

	public void addWorkUnit(String name, String unit, String job, ArrayList<Employer> lEmp) {
		// TODO Auto-generated method stub
		WorkUnit e = new WorkUnit(name,job,unit);								
		for (Employer emp: lEmp){
			e.addEmployer(emp);
		}
		lWorkUnit.add(e);
	} 
}
